const callAppMethod = (config) => {
  const callbackName = config.method + "Callback";
  const params = config.params

  for (const key in params) {
    if (typeof params[key] === 'function') {
      params[key] = params[key].bind(config)
    }
  }

  window[callbackName] = params;

  AppSDK.postMessage(JSON.stringify({ ...config, callbackName }));
}

export const scanCode = (params) => {
  callAppMethod({
    method: "ScanCode",
    params
  })
}

export const navigator = (params) => {
  callAppMethod({
    method: "Navigator",
    params
  })
}

export const blueWire = (params) => {
  callAppMethod({
    method: "BlueWire",
    params
  })
}